package weaver.interfaces.cese.duss.action.fee;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.cese.duss.ceseutil.CostUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 差旅申请流程接口
 * @ModifyLog:
 **/
/*
 *@Description: 1、出差申请时根据活动、费用科目进行预算的占用；
 * （流程完成后转建模，通过建模进行预算占用，根据单据日期进行二级预算的占用，同步更新一级预算）
 *@Author: Dusongsong
 *@Date: 2020/10/23
 */
public class WeaTravelRequestAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        writeLog( "----WeaTravelRequestAction-------" + requestid );
        try {
            rs.executeQuery( "select id,yshd,sqrq,cblrzx from " + tablename + " where requestid=?", requestid );
            rs.next();
            String mainid = Util.null2String( rs.getString( "id" ) );//mainid
            String yshd = Util.null2String( rs.getString( "yshd" ) );//预算活动
            String sqrq = Util.null2String( rs.getString( "sqrq" ) );//申请日期
            String cblrzx = Util.null2String( rs.getString( "cblrzx" ) );//成本利润中心
            if (yshd != "") {
                //明细表1
                String yslx = "0";//占用
                CostUtil.deleteYszxxxb( requestid );
                rs.executeQuery( "select fykm,yjfy from " + tablename + "_dt1 where mainid=?", mainid );
                while (rs.next()) {
                    String fykm = Util.null2String( rs.getString( "fykm" ) );//费用科目
                    String yjfy = Util.null2String( rs.getString( "yjfy" ) );//预计费用
                    //费用报销信息更新到预算执行信息表
                    CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, sqrq, yjfy, yslx, sqrq );
                }
                //明细表2
                rs.executeQuery( "select fykm,yjfy from " + tablename + "_dt2 where mainid=?", mainid );
                while (rs.next()) {
                    String fykm = Util.null2String( rs.getString( "fykm" ) );//费用科目
                    String yjfy = Util.null2String( rs.getString( "yjfy" ) );//预计费用
                    CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, sqrq, yjfy, yslx, sqrq );
                }
                //明细表3
                rs.executeQuery( "select fykm,hdje from " + tablename + "_dt3 where mainid=?", mainid );
                while (rs.next()) {
                    String fykm = Util.null2String( rs.getString( "fykm" ) );//费用科目
                    String hdje = Util.null2String( rs.getString( "hdje" ) );//核定金额
                    CostUtil.insertYszxxxb( requestid, yshd, fykm, cblrzx, sqrq, hdje, yslx, sqrq );
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
